<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加骑手</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="horsemanNumber" id="horsemanNumber" lay-verify="required" lay-reqtext="用户名不得为空" placeholder="请输入用户名"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">骑手姓名</label>
        <div class="layui-input-block">
            <input type="text" name="horsemanName" id="horsemanName" lay-verify="required" lay-reqtext="真实姓名不能为空" placeholder="请输入真实姓名"
                   value="" class="layui-input">
        </div>
    </div>
    <!--TODO 产品类别要从后端接口数据中获取，这里暂时写死！-->
    <div class="layui-form-item">
        <label class="layui-form-label">骑手类型</label>
        <div class="layui-input-block">
            <select name="horsemanType" id="horsemanType" lay-filter="horsemanType" lay-verify="required">
                <option value="">--请选择--</option>
                <option value="1">加盟骑手</option>
                <option value="2">合作骑手</option>
                <option value="3">自营骑手</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">骑手星级</label>
        <div class="layui-input-block">
            <select name="horsemanStarLevel" id="horsemanStarLevel" lay-filter="horsemanStarLevel" lay-verify="required">
                <option value="">--请选择--</option>
                <option value="0.00">八星</option>
                <option value="0.03">七星</option>
                <option value="0.06">六星</option>
                <option value="0.08">五星</option>
                <option value="0.1">四星</option>
                <option value="0.13">三星</option>
                <option value="0.15">二星</option>
                <option value="0.18">一星</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" name="horsemanPassword" id="horsemanPassword" lay-verify="required"
                   lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">确认密码</label>
        <div class="layui-input-block">
            <input type="password"  placeholder="请输入确认密码" lay-reqtext="确认密码不能为空"
                   lay-verify="required|confirmPass"     value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">负责区域</label>
        <div class="layui-input-block">
            <input type="text" name="horsemanArea" id="horsemanArea" placeholder="请输入区域"
                   lay-reqtext="区域不能为空" value="" class="layui-input" lay-verify="required">
        </div>
    </div>
    <!--TODO 上传之后图标需要显示出来-->
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">图标</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="file">
                <i class="layui-icon">&#xe67c;</i>点击上传
            </button>
            <tip>只能上传jpg/png文件，且不能超过500KB</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认提交</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form'], function () {
        var icon = '';
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#file', //绑定元素
            url: '', //上传接口
            size: 500,
            done: function(res){
                //上传完毕回调
                //图片上传地址
                icon = res.content
                console.log(icon);
                console.log(res);
            },
            error: function(){
                //请求异常回调
                console.log("网络错误！")
            }
        });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data.field)
            data.field.file = icon
            $.ajax({
                type: "post",
                url: "../horseman/horsemanAdd",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (result) {
                    if (result.result == "success") {
                        layer.msg("新增成功~！！");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        //parent.$("#shousuobtn",parent.document).trigger('click');	//子页面局部刷新父页面事件
                        window.parent.document.getElementById("shousuobtn").click();
                    }else if (result.result == "error"){
                        layer.msg('骑手新增失败~~！！');
                    }
                },
                error: function () {
                    console.log("网络出错！请重新连接")
                }
            });

            return false;
        });

        form.verify({
            confirmPass:function(value){
                if($('input[name=horsemanPassword]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });

    });
</script>
</body>
</html>